首页
<p/>
{$user.nickname}
<p/>
<a href="{:U('home/user/login')}">登录</a>
<div>
    <p>共续命:<span data-bind="text:count.curCount"></span>秒</p>
    <p>距离下一个至宝:<span data-bind="text:count.next"></span>秒</p>
    <p>已累积:<span data-bind="text:count.gift"></span>个至宝</p>
</div>
<div data-bind="foreach:giftList">
    <p>
        <img src="" height="50px" width="50px" data-bind="attr:{'src':logo}"/>
        <p>
            <span data-bind="text:name"></span>
            <br />
            <span>解锁需要：</span><span data-bind="text:count"></span>
        </p>
        <p data-bind="text:percent"></p>
    </p>
    <hr />
</div>
<script type="text/javascript" src="__PUBLIC__/Home/ui3/js/lib/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/Home/ui3/js/lib/knockout-2.3.0.js"></script>
<script type="text/javascript">
    var curCount = {$curCount};
    var giftList = {$giftList|json_encode};
    $(function(){
        viewModel = {
            giftList : ko.observableArray([]),
            count : {
                curCount : ko.observable(curCount),
                next : ko.observable(0),
                gift : ko.observable(1),
            },
        };
        ko.applyBindings(viewModel);

        viewModel.count.gift(parseInt(curCount/2000)+1);



        var list = [];
        $.each(giftList, function(index, el) {
            var percent = '0%';
            if (curCount >= el.unlockcount) {
                percent = '100%';
            } else {
                percent = Math.round(curCount*100/el.unlockcount) + '%';
                if (viewModel.count.next() == 0) {
                    viewModel.count.next(el.unlockcount - curCount);
                }
            }
            var gift = {
                name : el.name,
                logo : el.logo,
                count : el.unlockcount,
                percent : percent,
            };
            list.push(gift);
        });
        viewModel.giftList(list);
    });
</script>